//请帮我写一个基础的store，使用pinia，包含一个state和一个action
import { defineStore } from "pinia";
import { getRoleListApi, addRoleApi, deleteRoleApi } from "@/api/role";

export const useRoleStore = defineStore("myStore", {
  state: () => ({
    // 这里定义你的状态
    roleList: [],
    total: 0,
  }),
  getters: {},
  actions: {
    // 获取角色列表action
    async getRoleListAction(params) {
      const { rows, total } = await getRoleListApi(params);
      this.roleList = rows;
      this.total = total;
    },
    // 添加角色事件
    async addRoleAction(data) {
      await addRoleApi(data);
    },
    // 删除角色事件
    async deleteRoleAction(id) {
      await deleteRoleApi(id);
    },
  },
});

export default useRoleStore;
